/**
 * Created by jaylinwang on 1/28/16.
 */
requirejs.config({
    paths: {
        jquery: 'vendors/jquery/jquery-1.11.3.min',

        //requirejs plugin
        text: 'vendors/require/text',

        // Backbone library
        underscore: 'vendors/underscore/underscore-min',
        backbone: 'vendors/backbone/backbone-min',

        // bootstrap
        bootstrap: 'vendors/bootstrap/bootstrap.min',

        //表单验证
        validation: 'vendors/jquery-validation/jquery.validate.min',

        //图片轮播插件
        bxslider: 'vendors/jquery.bxslider/jquery.bxslider.min',

        //switcher
        switcher: 'vendors/switcher/switcher',

        //Select2
        select2: 'vendors/select2/select2.min',

        //全屏
        screenfull: 'vendors/screenfull/screenfull.min',

        //滚动插件
        iscroll: 'vendors/iscroll/iscroll',
        nicescroll: 'vendors/nicescroll/jquery.nicescroll.min',

        ////日期选择插件
        datepicker: 'vendors/datepicker/js/bootstrap-datepicker',

        //Toastr
        toastr: 'vendors/toastr/toastr',

        //echart
        echarts: 'vendors/echarts/echarts.min',

        //timeago
        timeago: 'vendors/jquery/jquery.timeago',

        //intro
        intro: 'vendors/intro/intro',

        //file upload
        widget: 'vendors/upload/jquery.ui.widget',
        'iframe-transport': 'vendors/upload/jquery.iframe-transport',
        fileupload: 'vendors/upload/jquery.fileupload',


        //Views
        AppView: 'app/views/AppView',
        FilterView: 'app/views/FilterView',
        FormView: 'app/views/FormView',
        ModalView: 'app/views/ModalView',
        ConfirmView: 'app/views/ConfirmView',
        MenuView: 'app/views/MenuView',
        PageView: 'app/views/PageView',
        RootView: 'app/views/RootView',

        formValidation: 'app/utils/form.validation',
        pageDisplay: 'app/utils/page.display',

        views: 'app/views',

        templates: 'app/templates',
    },
    shim: {
        jquery: {
            exports: '$'
        },
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        switchery: {
            exports: 'Switchery'
        },
        toastr: {
            exports: 'Toastr'
        },
        bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
        },
        alertify: {
            deps: ['jquery'],
            exports: 'Alertify'
        },
        validation: {
            deps: ['jquery'],
            exports: '$.fn.validate'
        },
        bxslider: {
            deps: ['jquery'],
            exports: '$.fn.bxslider'
        },
        select2: {
            deps: ['jquery', 'bootstrap'],
            exports: '$.fn.select2'
        },
        morris: {
            deps: ['jquery', 'raphael'],
            exports: 'Morris'
        },
        fileupload: {
            deps: ['jquery', 'widget'],
            exports: 'fileupload'
        }
    }
});
require(['jquery', 'underscore', 'AppView', 'FilterView', 'FormView', 'ModalView', 'MenuView', 'ConfirmView', 'bootstrap'],
    function($, _, AppView, FilterView, FormView, ModalView, MenuView, ConfirmView) {
        var view = new AppView;
        initialize();

        function initialize() {
            initViews();
        }

        //初始化视图
        function initViews() {
            view.filterView = new FilterView;
            view.formView = new FormView;
            view.modalView = new ModalView;
            view.menuView = new MenuView;
            view.confirmView = new ConfirmView;

            var $page = $('#Page'),
                scriptPath = $page.data('script-path');


            if (!_.isUndefined(scriptPath) && !_.isNull(scriptPath)) {
                require([scriptPath], function(View) {
                    new View();
                });
            }
        }
    });
